<template>
	<view class="content">
		<view class="top">
			<text>您好,</br>欢迎使用小格社区</text>
		</view>
		<view class="form">
			<view class="item">
				<text>用户名</text>
				<u--input placeholder="请输入用户名" border="surround" v-model="username"></u--input>
			</view>
			<view class="item">
				<text>密码</text>
				<u--input placeholder="请输入密码" border="surround" v-model="password" type="password"></u--input>
				<text class="forget">忘记密码?</text>
			</view>
			<u-button type="primary" shape="circle" text="登录" :disabled="disabled" @click="login"></u-button>
			<u-button type="primary" shape="circle" text="注册" color="#eee" @click="to_reg">
			</u-button>





		</view>
	</view>

</template>

<script>
	import {
		getLogin
	} from "../../api/user.js"
	export default {
		data() {
			return {
				username: '',
				password: '',
				disabled: false,

			}
		},
		onLoad() {

		},
		methods: {
			to_reg() {
				uni.navigateTo({
					url: "/pages/register/reg"
				})
			},
			login() {
				this.disabled = true
				let {
					username,
					password
				} = this

				if (username.trim().length == 0 || password.trim().length == 0) {
					uni.showToast({
						title: '请输入正确的用户名或密码',
						icon: "none"
					})
					this.disabled = false
					return
				}
				getLogin({
					mobile:username,
					password,
				}).then(res => {
					if (res.code == 200) {
						uni.setStorageSync('token', res.data);
						this.$store.dispatch('users/getUserInfo').then((v) => {

						
							this.disabled = false
							this.username = ''
							this.password = ''
							let {
								mobile
							} = v.data
							if (mobile == 1) {
								uni.showToast({
									title:res.msg+ ',请先绑定手机号',
									icon: "none"
								})
								setTimeout(()=>{        
									uni.hideToast()
									uni.switchTab({
										url:'../user/user'
									})
									
									 },1000)
							} else {uni.showToast({
									title:res.msg,
									icon: "none"
								});
								setTimeout(() => {
									uni.hideToast()
									uni.switchTab({
										url: "../index/index"
									})
								}, 2000);
							}
						})

					} else {
						this.disabled = false
						uni.showToast({
							title: res.msg,
							icon: "none"
						});
					}
				})



			},
			to_login() {
				uni.navigateTo({
					url: '../login/login'
				})
			},
			lock() {
				this.checked = !this.checked

				console.log(this.checked)
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		width: 750rpx;
		height: 100%;
		background: linear-gradient(to right, rgb(22, 136, 251), rgb(61, 167, 251));
		position: relative;
		box-sizing: border-box;

		.top {
			padding: 50rpx;
			// padding-bottom: 100rpx;
			color: #fff;
			font-size: 18px;
			font-weight: 400;
			line-height: 2;
		}

		.form {
			border-top-left-radius: 80rpx;
			border-top-right-radius: 80rpx;
			width: 750rpx;
			height: calc(100vh - 284rpx);
			background-color: #fff;
			box-sizing: border-box;
			padding: 50rpx;

			.item {
				box-sizing: border-box;
				margin-top: 20rpx;

				text {
					font-size: 14px;
					font-weight: 500;
				}
			}

			.forget {
				line-height: 2;
				font-size: 8px !important;
				color: #A7A5A5;
			}



		}
	}

	.u-input--radius[data-v-113bc24f],
	.u-input--square[data-v-113bc24f] {
		margin-top: 18rpx;
		padding: 0 !important;
		border: none;
	}

	.input-placeholder {
		font-size: 14px;
	}

	.u-button--circle[data-v-2bf0e569] {
		margin-top: 50rpx;
	}
</style>
